package cn.vc.content.controller.video;

import cn.vc.auth.entity.po.VUser;
import cn.vc.basicmodule.entity.Result;
import cn.vc.content.service.video.VideoLikeService;
import cn.vc.content.service.video.VideoService;
import cn.vc.content.util.SecurityUtil;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/videolike")
//@PreAuthorize("hasAnyAuthority('ordinary')")
public class VideoLikeController {
    @Resource(type = VideoLikeService.class)
    private VideoLikeService videoLikeService;
    @Resource()
    private StringRedisTemplate stringRedisTemplate;
    @Resource()
    private VideoService videoService;



    /**
     * <h2>点赞视频</h2>
     * @param id
     * @return
     */
    @PostMapping("/{id}")
    public Result<?> likeOrNot(@PathVariable("id") Long id) {
        VUser vUser = SecurityUtil.getUser();
        if (vUser==null) return Result.NOT_LOGGED_IN();
        boolean bo = videoLikeService.like(id, vUser.getId());
        if (bo) {
            videoService.like(id);
        }
        return new Result<>(bo);
    }

}
